package cn.qingxuntech.console.model

import cn.qingxuntech.console.enumration.ResponseMessage

class R<T> {

    var code: Int = 0
    var msg: String = ""
    var data: T? = null

    // 静态方法，success
    companion object {

        // success ，默认消息，带数据
        fun <T> success(data: T? = null): R<T> {
            return R<T>().apply {
                this.code = ResponseMessage.SUCCESS.code
                this.msg = ResponseMessage.SUCCESS.msg
                this.data = data
            }
        }

        // success ，带消息
        fun <T> success(msg: String = ResponseMessage.SUCCESS.msg, data: T? = null): R<T> {
            return R<T>().apply {
                this.code = ResponseMessage.SUCCESS.code
                this.msg = msg
                this.data = data
            }
        }

        // fail ，带消息
        fun <T> fail(msg: String = ResponseMessage.FAIL.msg): R<T> {
            return R<T>().apply {
                this.code = ResponseMessage.FAIL.code
                this.msg = msg
            }
        }
    }
}